﻿namespace Sidvall.LogManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class LogScopeItem : global::Sidvall.LogManager.UI.Entities.Core.BusinessBase, global::Sidvall.LogManager.Data.ILogScopeItem
    {
        #region Business Members

        #region CreatedTime

        private System.DateTime _CreatedTime = System.DateTime.UtcNow;
        partial void OnBeforeCreatedTimePropertyGet(Sidvall.Business.PropertyEventData<System.DateTime> eventData);
        partial void OnBeforeCreatedTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData);
        partial void OnAfterCreatedTimePropertyChanged();
        public System.DateTime CreatedTime
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.DateTime> eventData = new Sidvall.Business.PropertyEventData<System.DateTime>(Sidvall.Business.ValidationManager.GetValidDateTime(_CreatedTime));
                OnBeforeCreatedTimePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData = new Sidvall.Business.PropertyChangeEventData<System.DateTime>(value, _CreatedTime);
                OnBeforeCreatedTimePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("CreatedTime", eventData.Value, true, true, true);
                    OnAfterCreatedTimePropertyChanged();
                }
            }
        }

        #endregion
        #region EventTypeId

        private global::Sidvall.Logging.EventType _EventTypeId = global::Sidvall.Logging.EventType.Information;
        partial void OnBeforeEventTypeIdPropertyGet(Sidvall.Business.PropertyEventData<global::Sidvall.Logging.EventType> eventData);
        partial void OnBeforeEventTypeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.Logging.EventType> eventData);
        partial void OnAfterEventTypeIdPropertyChanged();
        public global::Sidvall.Logging.EventType EventTypeId
        {
            get
            {
                Sidvall.Business.PropertyEventData<global::Sidvall.Logging.EventType> eventData = new Sidvall.Business.PropertyEventData<global::Sidvall.Logging.EventType>(_EventTypeId);
                OnBeforeEventTypeIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<global::Sidvall.Logging.EventType> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.Logging.EventType>(value, _EventTypeId);
                OnBeforeEventTypeIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("EventTypeId", eventData.Value, true, true, true);
                    OnAfterEventTypeIdPropertyChanged();
                }
            }
        }

        #endregion
        #region IdentityAuthenticationType

        private string _IdentityAuthenticationType = string.Empty;
        partial void OnBeforeIdentityAuthenticationTypePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeIdentityAuthenticationTypePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterIdentityAuthenticationTypePropertyChanged();
        public string IdentityAuthenticationType
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_IdentityAuthenticationType);
                OnBeforeIdentityAuthenticationTypePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _IdentityAuthenticationType);
                OnBeforeIdentityAuthenticationTypePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IdentityAuthenticationType", eventData.Value, true, true, true);
                    OnAfterIdentityAuthenticationTypePropertyChanged();
                }
            }
        }

        #endregion
        #region IdentityName

        private string _IdentityName = string.Empty;
        partial void OnBeforeIdentityNamePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeIdentityNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterIdentityNamePropertyChanged();
        public string IdentityName
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_IdentityName);
                OnBeforeIdentityNamePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _IdentityName);
                OnBeforeIdentityNamePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IdentityName", eventData.Value, true, true, true);
                    OnAfterIdentityNamePropertyChanged();
                }
            }
        }

        #endregion
        #region LogScopeId

        private long _LogScopeId = 0L;
        partial void OnBeforeLogScopeIdPropertyGet(Sidvall.Business.PropertyEventData<long> eventData);
        partial void OnBeforeLogScopeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterLogScopeIdPropertyChanged();
        public long LogScopeId
        {
            get
            {
                Sidvall.Business.PropertyEventData<long> eventData = new Sidvall.Business.PropertyEventData<long>(_LogScopeId);
                OnBeforeLogScopeIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _LogScopeId);
                OnBeforeLogScopeIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("LogScopeId", eventData.Value, true, true, true);
                    OnAfterLogScopeIdPropertyChanged();
                }
            }
        }

        #endregion
        #region LogScopeItemId

        private System.Nullable<long> _LogScopeItemId = null;
        partial void OnBeforeLogScopeItemIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData);
        partial void OnBeforeLogScopeItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterLogScopeItemIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public System.Nullable<long> LogScopeItemId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<long>>(_LogScopeItemId);
                OnBeforeLogScopeItemIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _LogScopeItemId);
                OnBeforeLogScopeItemIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("LogScopeItemId", eventData.Value, true, true, true);
                    OnAfterLogScopeItemIdPropertyChanged();
                }
            }
        }

        #endregion
        #region Message

        private string _Message = string.Empty;
        partial void OnBeforeMessagePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeMessagePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterMessagePropertyChanged();
        public string Message
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Message);
                OnBeforeMessagePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Message);
                OnBeforeMessagePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Message", eventData.Value, true, true, true);
                    OnAfterMessagePropertyChanged();
                }
            }
        }

        #endregion
        #region Title

        private string _Title = string.Empty;
        partial void OnBeforeTitlePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeTitlePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterTitlePropertyChanged();
        public string Title
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Title);
                OnBeforeTitlePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Title);
                OnBeforeTitlePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Title", eventData.Value, true, true, true);
                    OnAfterTitlePropertyChanged();
                }
            }
        }

        #endregion
        #region ServerConnectionId

        private System.Nullable<System.Int32> _ServerConnectionId = null;
        partial void OnBeforeServerConnectionIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<System.Int32>> eventData);
        partial void OnBeforeServerConnectionIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>> eventData);
        partial void OnAfterServerConnectionIdPropertyChanged();
        public System.Nullable<System.Int32> ServerConnectionId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<System.Int32>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<System.Int32>>(_ServerConnectionId);
                OnBeforeServerConnectionIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.Int32>>(value, _ServerConnectionId);
                OnBeforeServerConnectionIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ServerConnectionId", eventData.Value, true, true, true);
                    OnAfterServerConnectionIdPropertyChanged();
                }
            }
        }

        #endregion
        #region LogScope

        private LogScope _LogScope;
        partial void OnBeforeLogScopePropertyChanged(Sidvall.Business.PropertyChangeEventData<LogScope> eventData);
        partial void OnAfterLogScopePropertyChanged();
        public LogScope LogScope
        {
            get
            {
                return _LogScope;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<LogScope> eventData = new Sidvall.Business.PropertyChangeEventData<LogScope>(value, _LogScope);
                OnBeforeLogScopePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("LogScope", eventData.Value, true, true, false);
                    OnAfterLogScopePropertyChanged();
                }
            }
        }

        #endregion
        #region LogScopeItemCategories

        private LogScopeItemCategoryCollection _LogScopeItemCategories;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public LogScopeItemCategoryCollection LogScopeItemCategories
        {
            get
            {
                return _LogScopeItemCategories;
            }
            internal set
            {
                LoadInstanceField("LogScopeItemCategories", value, true, false, false);
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadLogScopeItemCategories

        public void LoadLogScopeItemCategories(LogScopeItemCategoryCollection value)
        {
            LoadInstanceField("LogScopeItemCategories", value, true, true, false);
        }

        #endregion
        #region LoadLogScopeItemCategoriesAsync

        public async System.Threading.Tasks.Task<LogScopeItemCategoryCollection> LoadLogScopeItemCategoriesAsync()
        {
            return await LoadLogScopeItemCategoriesAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<LogScopeItemCategoryCollection> LoadLogScopeItemCategoriesAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchListCriteria<global::Sidvall.LogManager.Data.Fields.LogScopeItemCategoryField, global::Sidvall.LogManager.Data.Relations.LogScopeItemCategoryRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.LogManager.UI.SystemContext.Current.DataPortal.LogScopeItemManager.LoadLogScopeItemCategoriesAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.LogScopeItemCategories;
        }

        #endregion
        #region LoadLogScopeAsync

        public async System.Threading.Tasks.Task<LogScope> LoadLogScopeAsync()
        {
            return await LoadLogScopeAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<LogScope> LoadLogScopeAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.LogManager.Data.Fields.LogScopeField, global::Sidvall.LogManager.Data.Relations.LogScopeRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.LogManager.UI.SystemContext.Current.DataPortal.LogScopeItemManager.LoadLogScopeAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.LogScope;
        }
        public LogScope LoadLogScope(LogScope item)
        {
            LoadInstanceField("LogScope", item, true, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public LogScopeItem Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public LogScopeItem Copy()
        {
            return Copy(null);
        }
        public LogScopeItem Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new LogScopeItem();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.LogManager.Data.ILogScopeItem item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.LogManager.Data.ILogScopeItem item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(LogScopeItem destination, global::Sidvall.LogManager.Data.ILogScopeItem source, Sidvall.Data.CopySettings copySettings);
        private void Import(LogScopeItem destination, global::Sidvall.LogManager.Data.ILogScopeItem source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(LogScopeItem destination, LogScopeItem source, Sidvall.Data.CopySettings copySettings);
        private void Import(LogScopeItem destination, LogScopeItem source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.LogManager.Data.ILogScopeItem, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<LogScopeItem> SaveItemAsync()
        {
            return await global::Sidvall.LogManager.UI.SystemContext.Current.DataPortal.LogScopeItemManager.SaveItemAsync(this);
        }
        public async System.Threading.Tasks.Task<LogScopeItem> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.LogManager.UI.SystemContext.Current.DataPortal.LogScopeItemManager.SaveItemAsync(this, mode);
        }
        public async System.Threading.Tasks.Task<LogScopeItem> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.LogManager.UI.SystemContext.Current.DataPortal.LogScopeItemManager.SaveItemAsync(this, settings);
        }
        public async System.Threading.Tasks.Task<LogScopeItem> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.LogManager.UI.SystemContext.Current.DataPortal.LogScopeItemManager.SaveItemAsync(this, settings, strategyContext, objectParameters);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemManager.Initialize(this, settings);
        }

        #endregion
        
        #region ILogScopeItem Members

        System.DateTime global::Sidvall.LogManager.Data.ILogScopeItem.CreatedTime
        {
            get
            {
                return this._CreatedTime;
            }
            set
            {
                this._CreatedTime = value;
            }
        }
        global::Sidvall.Logging.EventType global::Sidvall.LogManager.Data.ILogScopeItem.EventTypeId
        {
            get
            {
                return this._EventTypeId;
            }
            set
            {
                this._EventTypeId = value;
            }
        }
        string global::Sidvall.LogManager.Data.ILogScopeItem.IdentityAuthenticationType
        {
            get
            {
                return this._IdentityAuthenticationType;
            }
            set
            {
                this._IdentityAuthenticationType = value;
            }
        }
        string global::Sidvall.LogManager.Data.ILogScopeItem.IdentityName
        {
            get
            {
                return this._IdentityName;
            }
            set
            {
                this._IdentityName = value;
            }
        }
        long global::Sidvall.LogManager.Data.ILogScopeItem.LogScopeId
        {
            get
            {
                return this._LogScopeId;
            }
            set
            {
                this._LogScopeId = value;
            }
        }
        System.Nullable<long> global::Sidvall.LogManager.Data.ILogScopeItem.LogScopeItemId
        {
            get
            {
                return this._LogScopeItemId;
            }
            set
            {
                this._LogScopeItemId = value;
            }
        }
        string global::Sidvall.LogManager.Data.ILogScopeItem.Message
        {
            get
            {
                return this._Message;
            }
            set
            {
                this._Message = value;
            }
        }
        string global::Sidvall.LogManager.Data.ILogScopeItem.Title
        {
            get
            {
                return this._Title;
            }
            set
            {
                this._Title = value;
            }
        }
        System.Nullable<System.Int32> global::Sidvall.LogManager.Data.ILogScopeItem.ServerConnectionId
        {
            get
            {
                return this._ServerConnectionId;
            }
            set
            {
                this._ServerConnectionId = value;
            }
        }
        global::Sidvall.LogManager.Data.ILogScope global::Sidvall.LogManager.Data.ILogScopeItem.LogScope
        {
            get
            {
                return this._LogScope;
            }
            set
            {
                UpdateChildProperty(this._LogScope, value);
                this._LogScope = value as LogScope;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.LogManager.Data.ILogScopeItemCategory> global::Sidvall.LogManager.Data.ILogScopeItem.LogScopeItemCategories
        {
            get
            {
                return this._LogScopeItemCategories;
            }
        }
        void global::Sidvall.LogManager.Data.ILogScopeItem.SetLogScopeItemCategories(Sidvall.Data.IDataRowProvider<global::Sidvall.LogManager.Data.ILogScopeItemCategory> items)
        {
            UpdateChildProperty(this._LogScopeItemCategories, items);
            this._LogScopeItemCategories = items as LogScopeItemCategoryCollection;
        }

        #endregion

        #endregion
        #region Constructors

        public LogScopeItem()
        {
        }

        public LogScopeItem(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}